
#include "Custom_config.h"


#ifdef AC209_28PIN

   #define            ADKEY_USE_P07
                #define SET_MUTE_PORT_DIR()	P2DIR &= ~(BIT(6))  //P0IE &= 0xfe;//P3DIR &= ~0x10//DACCON0|=0x80;
               #define SET_MUTE_PORT_PU() 			P2PU |= BIT(6) ///P3PU |= 0x10//
               #define MUTE_PORT_HIGH()			P26  =1//P34=1//
               #define MUTE_PORT_LOW()			P26  =0//	P34  =0//
           
               #define play_led_seg_out()  P2DIR &= ~(BIT(7));P2PU |= BIT(7); //P0DIR &= ~(1<<2);P0PU |= (1<<2) ;P3DIR |= (1<<4);P3PU &=~ (1<<4);P3PD&=~ (1<<4);DACCON0|=0x80;
           
              #define PLAY_STATUS_PORT P27
               #define iic_data_out()    P0DIR &= ~(1<<1);P0PU |= (1<<1) ;
               #define iic_data_in()     P0DIR |= (1<<1);P0PU |= (1<<1);
               #define iic_data_r()      P01
               #define iic_data_h()      P01 = 1
               #define iic_data_l()      P01 = 0
               
               #define iic_clk_out()    P0DIR &= ~(1);P0PU |= (1);
               #define iic_clk_h()      P00 = 1
               #define iic_clk_l()      P00 = 0
                                  #ifdef LINE_IN_DETECT_USE_P27
                                  #define  aux_detect_in()     P2DIR |= BIT(7);P2PU |= BIT(7);//DACCON0|=0x80; 
                                  #define  AUX_DETECT_GPIO  P27
                                  #define  aux_detect_in_off()        P2DIR &= ~BIT(7); //linein check port
                                  #else
                                  #define  aux_detect_in()      P0DIR |= BIT(2);P0PU |= BIT(2);
                                  #define  AUX_DETECT_GPIO  P02
                                  #define  aux_detect_in_off()        P0DIR &= ~BIT(2); //linein check port
                                  #endif
           		   
           #define   EARPHONE_DETECT_GPIO  P27
           #define   earphone_detect_in()   P2DIR |= 0x80;P2PU &= ~0x80;  //DACCON0|=0x80;
           
           #define power_key_detect_in()		 P2DIR &=~(1<<7);P2PU |= (1<<7);P27 =1;;P2DIR |= (1<<7);P2PU &= ~(1<<7);//DACCON0|=0x80;
           #define POWER_KEY_PORT		P27//P34=1//
           #define power_ctl(n)  			P2DIR &= ~(1<<6);P2PU |= (1<<6);P26 = n//DACCON0|=0x80;

#elif  defined(K738_LHD_LTB1)
   #define            ADKEY_USE_P07

               #define play_led_seg_out()  P0DIR &= ~(BIT(2));P2PU |= BIT(2); //P0DIR &= ~(1<<2);P0PU |= (1<<2) ;P3DIR |= (1<<4);P3PU &=~ (1<<4);P3PD&=~ (1<<4);DACCON0|=0x80;
           
              #define PLAY_STATUS_PORT P02
               #define iic_data_out()    P0DIR &= ~(1<<1);P0PU |= (1<<1) ;
               #define iic_data_in()     P0DIR |= (1<<1);P0PU |= (1<<1);
               #define iic_data_r()      P01
               #define iic_data_h()      P01 = 1
               #define iic_data_l()      P01 = 0
               
               #define iic_clk_out()    P0DIR &= ~(1);P0PU |= (1);
               #define iic_clk_h()      P00 = 1
               #define iic_clk_l()      P00 = 0

		 #define SET_MUTE_PORT_DIR()	;//P2DIR &= ~(BIT(6))  //P0IE &= 0xfe;//P3DIR &= ~0x10//DACCON0|=0x80;
               #define SET_MUTE_PORT_PU() 	;//		P2PU |= BIT(6) ///P3PU |= 0x10//
               #define MUTE_PORT_HIGH()		;//	P26  =1//P34=1//
               #define MUTE_PORT_LOW()		;//	P26  =0//	P34  =0//

#elif  defined(LHD_MP8)
   #define            ADKEY_USE_P07

               #define play_led_seg_out()  P0DIR &= ~(BIT(2));P0PU |= BIT(2); //P0DIR &= ~(1<<2);P0PU |= (1<<2) ;P3DIR |= (1<<4);P3PU &=~ (1<<4);P3PD&=~ (1<<4);DACCON0|=0x80;
           
              #define PLAY_STATUS_PORT P02
               #define iic_data_out()    P0DIR &= ~(1<<1);P0PU |= (1<<1) ;
               #define iic_data_in()     P0DIR |= (1<<1);P0PU |= (1<<1);
               #define iic_data_r()      P01
               #define iic_data_h()      P01 = 1
               #define iic_data_l()      P01 = 0
               
               #define iic_clk_out()    P0DIR &= ~(1);P0PU |= (1);
               #define iic_clk_h()      P00 = 1
               #define iic_clk_l()      P00 = 0

                #define SET_MUTE_PORT_DIR()	;//P0DIR &= ~(BIT(2))  //P0IE &= 0xfe;//P3DIR &= ~0x10//DACCON0|=0x80;
               #define SET_MUTE_PORT_PU() 		;//	P0PU |= BIT(2) ///P3PU |= 0x10//
               #define MUTE_PORT_HIGH()		;//	P02  =1//P34=1//
               #define MUTE_PORT_LOW()		;//	P02  =0//	P34  =0//


#elif  defined(K678_TN893)
#define ADKEY_USE_P02
           	#define SET_MUTE_PORT_DIR()	;//DACCON0|=0x80;P2DIR &= ~(BIT(6))  //P0IE &= 0xfe;//P3DIR &= ~0x10//
               #define SET_MUTE_PORT_PU() 		;//	P2PU |= BIT(6) ///P3PU |= 0x10//
               #define MUTE_PORT_HIGH()			;//P26  =1//P34=1//
               #define MUTE_PORT_LOW()			;//P26  =0//	P34  =0//        
              #define play_led_seg_out()    P0DIR &= ~BIT(5);P0PU |= BIT(5);
               #define PLAY_STATUS_PORT  P05
           
           	
               #define iic_data_out()    P1DIR &= ~(BIT(7));P1PU |=BIT(7);
               #define iic_data_in()     P1DIR |= BIT(7);P1PU |=BIT(7);
               #define iic_data_r()      P17
               #define iic_data_h()      P17 = 1
               #define iic_data_l()      P17 = 0
               
               #define iic_clk_out()    P0DIR &= ~BIT(5);P0PU |= BIT(5);
               #define iic_clk_h()      P05 = 1
               #define iic_clk_l()      P05 = 0	

#elif defined(K589_YJH_589)
#define ADKEY_USE_P02
           	#define SET_MUTE_PORT_DIR()	;//DACCON0|=0x80;P2DIR &= ~(BIT(6))  //P0IE &= 0xfe;//P3DIR &= ~0x10//
               #define SET_MUTE_PORT_PU() 		;//	P2PU |= BIT(6) ///P3PU |= 0x10//
               #define MUTE_PORT_HIGH()			;//P26  =1//P34=1//
               #define MUTE_PORT_LOW()			;//P26  =0//	P34  =0//        
              #define play_led_seg_out()    P2DIR &= ~BIT(4);P2PU |= BIT(4);P2DIR |= BIT(3);
               #define PLAY_STATUS_PORT  P24
             #define charge_det_in()    P2DIR |= BIT(5);P2PD|=BIT(5);
               #define CHARGE_DET_GPIO  P25
           	
               #define iic_data_out()    P1DIR &= ~(BIT(7));P1PU |=BIT(7);
               #define iic_data_in()     P1DIR |= BIT(7);P1PU |=BIT(7);
               #define iic_data_r()      P17
               #define iic_data_h()      P17 = 1
               #define iic_data_l()      P17 = 0
               
               #define iic_clk_out()    P0DIR &= ~BIT(5);P0PU |= BIT(5);
               #define iic_clk_h()      P05 = 1
               #define iic_clk_l()      P05 = 0	
#else

 #ifdef POWER_SAVE_SYSTEM
///ac209 48pin
#ifdef POWER_POWRE_KEY_P02	

#define power_key_detect_in()		 P0DIR |=(1<<2); P0PU &=~(1<<2);P0PD|=(1<<2);      //P0IE &= 0xfe;//P3DIR &= ~0x10//
#define POWER_KEY_PORT		P02//P34=1//
#else
#define power_key_detect_in()		 P0DIR |=(1<<4); P0PU &=~(1<<4);P0PD|=(1<<4);      //P0IE &= 0xfe;//P3DIR &= ~0x10//
#define POWER_KEY_PORT		P04//P34=1//

#endif
#ifdef POWER_CTL_P10	
#define power_ctl(n)  P1DIR &= ~0x01 ;P0PU |= 0x01;P10 = n
#else
#define power_ctl(n)  P0DIR &= ~0x02 ;P0PU |= 0x02;P01 = n
#endif
#endif


#ifdef MUTE_PORT_USE_P00

 #define SET_MUTE_PORT_DIR()	P0DIR &= ~0x01      //P0IE &= 0xfe;//P3DIR &= ~0x10//
#define SET_MUTE_PORT_PU() 			P0PU |= 0x01//P3PU |= 0x10//
#ifdef  PA_LOW_MUTE//
#define MUTE_PORT_HIGH()			P00  =0//P34=1//
#define MUTE_PORT_LOW()			P00  =1//	P34  =0//
#else
#define MUTE_PORT_HIGH()			P00  =1//P34=1//
#define MUTE_PORT_LOW()			P00  =0//	P34  =0//
#endif
#elif defined(MUTE_PORT_USE_P03)
 #define SET_MUTE_PORT_DIR()	P0DIR &=~(1<<3);   //P0IE &= 0xfe;//P3DIR &= ~0x10//
#define SET_MUTE_PORT_PU() 			P0PU |= (1<<3);//P3PU |= 0x10//
#define MUTE_PORT_HIGH()			P03  =1//P34=1//
#define MUTE_PORT_LOW()			P03 =0//	P34  =0//

#elif defined(MUTE_PORT_USE_P17)
 #define SET_MUTE_PORT_DIR()	P1DIR &=~(1<<7);   //P0IE &= 0xfe;//P3DIR &= ~0x10//
#define SET_MUTE_PORT_PU() 			P1PU |= (1<<7);//P3PU |= 0x10//
#define MUTE_PORT_HIGH()			P17  =1//P34=1//
#define MUTE_PORT_LOW()			P17 =0//	P34  =0//
#else
#define SET_MUTE_PORT_DIR()		P0DIR &= ~0x02      //P0IE &= 0xfe;//P3DIR &= ~0x10//
#define SET_MUTE_PORT_PU() 			P0PU |= 0x02//P3PU |= 0x10//
           #ifdef  PA_LOW_MUTE//
           #define MUTE_PORT_HIGH()			P01 =0//P34=1//
           #define MUTE_PORT_LOW()			P01  =1//	P34  =0//
           #else
           #define MUTE_PORT_HIGH()			P01  =1//P34=1//
           #define MUTE_PORT_LOW()			P01  =0//	P34  =0//
           #endif
#endif

   #ifdef POWER_CTL_P04
    #define powerdowm_ctl(n)  	 P0DIR &= ~(BIT(4));P0PU |= BIT(4); P04=n;
   #else
 #define powerdowm_ctl(n)  	 P0DIR &= ~(BIT(2));P0PU |= BIT(2); P02=n;

#endif


#ifdef JOG_KEY
#define JOG_detect_in() P1DIR |= 0xC0;P1PU |= 0xC0; 
#define JOG_PORT  P1
#endif


#define play_led_seg_out() P0DIR &= ~0x80;P0PU |= 0x80; 
#define PLAY_STATUS_PORT P07

#define  EARPHONE_DETECT_GPIO  P07
#define  earphone_detect_in()   P0DIR |= 0x80;P0PU &= ~0x80; 


#ifdef  LINE_IN_DETECT_USE_P01
#define  aux_detect_in()      P0DIR |= BIT(1);P0PU |= BIT(1);//linein check port
#define  AUX_DETECT_GPIO  P01
#define  aux_detect_in_off()        P0DIR &= ~BIT(1); //linein check port
#elif defined(LINE_IN_DETECT_USE_P34)
#define  aux_detect_in()      P3DIR |= BIT(4);P0PU |= BIT(4);//linein check port
#define  AUX_DETECT_GPIO  P34
#define  aux_detect_in_off()        P3DIR &= ~BIT(4); //linein check port
#elif defined(LINE_IN_DETECT_USE_P02)
#define  aux_detect_in()      P0DIR |= BIT(2);P0PU |= BIT(2);//linein check port
#define  AUX_DETECT_GPIO  P02
#define  aux_detect_in_off()        P0DIR &= ~BIT(2); //linein check port
#elif defined(LINE_IN_DETECT_USE_P06)
#define  aux_detect_in()      P0DIR |= BIT(6);P0PU |= BIT(6);//linein check port
#define  AUX_DETECT_GPIO  P06
#define  aux_detect_in_off()        P0DIR &= ~BIT(6); //linein check port
#elif defined(LINE_IN_DETECT_USE_P07)
#define  aux_detect_in()      P0DIR |= BIT(7);P0PU |= BIT(7);//linein check port
#define  AUX_DETECT_GPIO  P07
#define  aux_detect_in_off()        P0DIR &= ~BIT(7); //linein check port
#else
#define  aux_detect_in()      P0DIR |= BIT(4);P0PU |= BIT(4);//linein check port
#define  AUX_DETECT_GPIO  P04
#define  aux_detect_in_off()        P0DIR &= ~BIT(4); //linein check port
#endif

#ifdef  USER_CHARGR_DISPLAY
#ifdef CHARGR_DET_USER_VPP
  #define  charge_detect_in()      WKUPPND &=~ (1<<6); //P0DIR |= BIT(4);P0PU |= BIT(4);//linein check port
  #elif defined(CHARGR_DET_USE_P01)
 #define  charge_detect_in()       P0DIR |= BIT(1);P0PD|= BIT(1);
  #define  charge_status_port       P01
    #elif defined(CHARGR_DET_USE_P17)
 #define  charge_detect_in()       P1DIR |= BIT(7);P1PDA|= BIT(7);//P1PDA|= BIT(7);
  #define  charge_status_port       P17
  #elif defined(CHARGR_DET_USE_P02)
 #define  charge_detect_in()       P0DIR |= BIT(2);P0PD|= BIT(2);
  #define  charge_status_port       P02
    #elif defined(CHARGR_DET_USE_P07)
 #define  charge_detect_in()       P0DIR |= BIT(7);P0PD|= BIT(7);
  #define  charge_status_port       P07
#else
 #define  charge_detect_in()       P0DIR |= BIT(4);P0PD|= BIT(4);
  #define  charge_status_port       P04
 #endif
#endif

#ifdef I2C_USE_POO_P01_PORT

#define iic_data_out()    P0DIR &= ~(1<<1);P0PU |= (1<<1)
#define iic_data_in()     P0DIR |= (1<<1);P0PU |= (1<<1)
#define iic_data_r()      P01
#define iic_data_h()      P01 = 1
#define iic_data_l()      P01 = 0
#define iic_clk_out()    P0DIR &= ~(1<<0);P0PU |= (1<<0)
#define iic_clk_h()      P00= 1
#define iic_clk_l()      P00 = 0
#else
#define iic_data_out()    P0DIR &= ~(1<<2);P0PU |= (1<<2)
#define iic_data_in()     P0DIR |= (1<<2);P0PU |= (1<<2)
#define iic_data_r()      P02
#define iic_data_h()      P02 = 1
#define iic_data_l()      P02 = 0
#define iic_clk_out()    P0DIR &= ~(1<<3);P0PU |= (1<<3)
#define iic_clk_h()      P03 = 1
#define iic_clk_l()      P03 = 0
#endif




#endif


#ifdef  USE_IO_SWITCH_AP_MOD
#ifdef MP3_FM_SWITCH_PORT_P07
#define  MP3_FM_SWITCH_PORT_OUT()    P0DIR &= ~(BIT(7));P0PU |= BIT(7);
#define MP3_FM_SWITCH_PORT  P07
#elif   defined(MP3_FM_SWITCH_PORT_P06)
#define  MP3_FM_SWITCH_PORT_OUT()    P0DIR &= ~(BIT(6));P0PU |= BIT(6);
#define MP3_FM_SWITCH_PORT  P06
#elif   defined(MP3_FM_SWITCH_PORT_P17)
#define  MP3_FM_SWITCH_PORT_OUT()    P1DIR &= ~(BIT(7));P1PU |= BIT(7);
#define MP3_FM_SWITCH_PORT  P17
#elif   defined(MP3_FM_SWITCH_PORT_P04)
#define  MP3_FM_SWITCH_PORT_OUT()    P0DIR &= ~(BIT(4));P0PU |= BIT(4);
#define MP3_FM_SWITCH_PORT  P04
#endif
#endif



#if defined(LED_ROLLING_AND_LED_DISP)
#define   LED_COM6_init()        P0DIR &= ~(1<<2);P0DIR &= ~(1<<(2));
#define  LED_COM6  P02
#endif

#define led_com_out() P3DIR &= ~0x1F; P3HD = 0x1f,P3PD |= 0x1f; PWM4CON = 0xdf
#ifdef  K6049_SES_V001
#define led_seg_out() P1DIR &= ~0xFF
#else
#define led_seg_out() P1DIR &= ~0x7F
#endif

#define ADC_KEY_IO7    0xff
#define ADC_KEY_IO6    0xfe
#define ADC_KEY_IO5    0xfd
#define ADC_KEY_IO2    0xfa

#define ADC_VDD_12     0xf8
#define ADC_LDOIN      0xf9

#define LED_COM1   P30
#define LED_COM2   P31
#define LED_COM3   P32
#define LED_COM4   P33
#define LED_COM5   P34
#define LED_COM    P3
#define LED_SEG    P1
#define LED_COM_MASK   P3PU

